#!/usr/bin/env node

const fs = require('fs');
const file = process.argv[2] || __filename;
/*
if(!fs.existsSync(file)){
  console.error(`${file} not exist!`);
  return;
}*/

try{
  fs.readFile(file,'utf8',(err,data)=>{
    if(err) {
      console.error(err.message);
      return;
    }
  
    //data.split('\n');
    const lines = data.split('\n');
    for(let i = 1; i<=lines.length ;i++  ){
      console.log(`${i}\t${lines[i-1]}`);
    } 
 
  }
  );
}
catch(e){
  console.error(e.message);
  console.log('IS ERROR');
}
//文件为空
//
process.on('uncaughtException',(e)=>{
  console.log('FILE IS EMPTY');
});
